package Mytest;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

public class Nowtest extends JFrame implements ActionListener {
    private JTextField label2;
    private JPasswordField label5;
    public static void main(String[] args) {
        Nowtest nowtest=new Nowtest();
        nowtest.init();
    }
    private URL getFilePath(String path){
        return this.getClass().getClassLoader().getResource(path);
    }
    private void init(){
        //北部
        JLabel north_label =new JLabel(new ImageIcon(("image/head.png")));
        //将控件添加到窗口中
        this.add(north_label,BorderLayout.NORTH);
        //西部
        JLabel west_label =new JLabel("注册账号");
        //创建容器
        JPanel west_panel=new JPanel();
        //将控件添加到窗口中
        west_panel.add(west_label);
        //将容器添加到窗口中
        this.add(west_panel,BorderLayout.WEST);
        //东部
        JLabel east_Jabel=new JLabel(new ImageIcon(("image/ercode.png")));
        //创建容器
        JPanel east_panel=new JPanel();
        //将控件添加到窗口中
        east_panel.add(east_Jabel);
        //将容器添加到窗口中
        this.add(east_panel,BorderLayout.EAST);
        //南部
        JButton sout_btn= new JButton(new ImageIcon("image/login.png"));
        //将容器添加到窗体中
        this.add(sout_btn,BorderLayout.SOUTH);
        //设置去背景
        sout_btn.setContentAreaFilled(false);
        //设置去边框
        sout_btn.setBorderPainted(false);
        //设置获取焦点时取消绘制
        sout_btn.setFocusPainted(false);
        //将控件添加到窗体中
        this.add(sout_btn,BorderLayout.SOUTH);


        //中部
        //创建容器
        JPanel center_panel=new JPanel(new GridLayout(3,3));
        //第一行第一列
        JLabel label1=new JLabel("qq号码");
        //第一行第二列
        JTextField jTextField1=new JTextField();
        //第一行第3列
        JButton button1=new JButton(new ImageIcon("image/clear.gif"));
      // button1.setBorderPainted(false);
       //button1.setBorderPainted(false);

        JLabel label2=new JLabel("QQ密码");
        JPasswordField jPasswordField=new JPasswordField();
        JLabel jLabel3 =new JLabel("忘记密码");

        JCheckBox label5=new JCheckBox("隐身登录");
        JCheckBox label6=new JCheckBox("记住密码");
        JLabel label7=new JLabel("申请密码保护");

        //设置文本颜色
        label7.setForeground(Color.BLUE);
        center_panel.add(label1);
        center_panel.add(jTextField1);
        center_panel.add(button1);
        center_panel.add(label2);
        center_panel.add(jPasswordField);
        center_panel.add(jLabel3);
        center_panel.add(label5);
        center_panel.add((label6));
        center_panel.add(label7);

        //this.getContentPane().setLayout(new FlowLayout());
        //添加容器
        this.add(center_panel,BorderLayout.CENTER);

        //设置标题
        this.setTitle("标题");
        //设置窗体大小
        this.setSize(430,330);
        //设置可视化
        this.setVisible(true);
        //设置退出程序
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
        //创建文本输入框
        JTextField jTextField =new JTextField();
        //将控件添加到窗体中
        this.add(jTextField,BorderLayout.CENTER);
    }
    public void actionPerformed(ActionEvent e){
        System.out.println("按钮点击了");
        //获取输入框的值
        String qq=label2.getText().toString().trim();
        String pwd=label5.getText().toString().trim();
        if("123456".equals(qq)&&"admin".equals(pwd)){
            System.out.println("登录成功");
            this.dispose();
            Chat chat=new Chat();
            chat.init();

            new Thread(){
                @Override
                public void run() {
                    super.run();
                }
            }.start();
        }
        else {
            JOptionPane.showMessageDialog(this,"用户名或密码错误");
        }
    }
}